﻿/// <reference path="../jquery/jquery-1.3.2-vsdoc.js" />
/// <reference path="Complaint.Namespaces.js" />
/// <reference path="Complaint.Common.js" />
/// Dependency: Script block from Index.aspx

var URL = Complaint.Common.SiteRoot + "/Search";
$(function() {
    $("#dateFrom").datepicker({ dateFormat: 'dd/mm/yy' });
    $("#dateTo").datepicker({ dateFormat: 'dd/mm/yy' });

    $("form input:text").keyup(function(evt) {
        if (evt.keyCode == '13') {
            evt.preventDefault();
            $("button#search").click();
        }
        return false;
    });

    $("button#search").click(function(evt) {
        var idlist = new Array();
        $("#categoryList").children().each(function() {
            idlist.push($(this).attr("id"));
        });

        $("div#category input#categoryIDs").val(idlist.ToJson());

        $.ajax({
            type: "POST",
            dataType: "html",
            timeout: 30000,
            url: URL,
            data: {
                keywords: $("#keywords").val(),
                dateFrom: $("#dateFrom").val(),
                dateTo: $("#dateTo").val(),
                categoryIds: $("#categoryIDs").val()
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                $("div.page-content").html(XMLHttpRequest.responseText);
            },
            success: function(result) { $("div#resultGrid").html(result); }
        });
    });
});